import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'af_bottom_input_type_state.dart';
import 'af_record_type_state.dart';

part 'af_bottom_input_field_view_model.g.dart';

@riverpod
class AfBottomInputTypeService extends _$AfBottomInputTypeService {
  @override
  AfBottomInputTypeState build() {
    return const AfBottomInputTypeState.input();
  }

  toggleEmoji() {
    state = state.maybeWhen(
      input: () => const AfBottomInputTypeState.emoji(),
      emoji: () => const AfBottomInputTypeState.input(),
      orElse: () => const AfBottomInputTypeState.emoji(),
    );
  }

  toggleFile() {
    state = state.maybeWhen(
      input: () => const AfBottomInputTypeState.file(),
      file: () => const AfBottomInputTypeState.input(),
      orElse: () => const AfBottomInputTypeState.file(),
    );
  }

  toggleRecord() {
    state = state.maybeWhen(
      input: () => const AfBottomInputTypeState.record(),
      record: () => const AfBottomInputTypeState.input(),
      orElse: () => const AfBottomInputTypeState.record(),
    );
  }

  editIn() {
    state = const AfBottomInputTypeState.input();
  }

  exitEdit() {
    state = const AfBottomInputTypeState.idle();
  }
}

@riverpod
class AfRecordTypeStateService extends _$AfRecordTypeStateService {
  @override
  AfRecordTypeState build() {
    return const AfRecordTypeState.idle();
  }

  record() {
    state = const AfRecordTypeState.recording();
  }

  cancel() {
    state = const AfRecordTypeState.recordCancel();
  }
}

@riverpod
class RecordLongPressMoveOffsetService
    extends _$RecordLongPressMoveOffsetService {
  @override
  Offset? build() {
    return null;
  }

  update(Offset offset) {
    state = offset;
  }

  reset() {
    state = null;
  }
}
